/* 
  Copyright (c) SilverLining 2015
  Date:    2016-1-7
  File:    GameObject.cpp  
  Description: 

*/

#include "stdafx.h"

using namespace System;
using namespace System::Security;
using namespace System::Runtime::InteropServices;

#include "shim_object.h"
#include "GameObject.h"
#include "Archiver.h"

using namespace m;
using namespace m::alloc;

namespace SL
{
	namespace M
	{
		GameObject::GameObject()
			: _ReadDelegate(gcnew ReadDelegate(this, &GameObject::Read)),
			_WriteDelegate(gcnew WriteDelegate(this, &GameObject::Write)), 
			_rGch(GCHandle::Alloc(_ReadDelegate)),
			_wGch(GCHandle::Alloc(_WriteDelegate)),
			NativePtr(new shim_object())
		{
			NativePtr->set_object(this);
		}

		GameObject::~GameObject()
		{
			GameObject::!GameObject();
		}

		GameObject::!GameObject()
		{
			if (NativePtr)
			{
				NativePtr->release();
			}

			if (_rGch != nullptr)
			{
				_rGch->Free();
			}

			if (_wGch != nullptr)
			{
				_wGch->Free();
			}
		}

		void GameObject::Read(Archiver ^ archiver)
		{
			// Implement me.
		}

		void GameObject::Read(m::archiver * archiver)
		{
			Archiver^ managedArchiver = gcnew Archiver(archiver);
			Read(managedArchiver);

			// Implement me.
		}

		void GameObject::Write(Archiver ^ archiver)
		{
			// Implement me.
		}

		void GameObject::Write(m::archiver * archiver)
		{
			Archiver^ managedArchiver = gcnew Archiver(archiver);
			Write(managedArchiver);

			// Implement me.
		}
	}
}
